import {
  SVAEUSERINFO,
  DELETE_USER_INFO
} from './constant'




export const saveUserInfoAction = userInfo => {
  const {
    token,
    user
  } = userInfo
  // 保存到localStorage中
  localStorage.setItem('token', token)
  localStorage.setItem('user', JSON.stringify(user))
  return {
    type: SVAEUSERINFO,
    userInfo

  }
}
export const deleteUserInfoAction = () => {
  localStorage.removeItem('token')
  localStorage.removeItem('user')
  return {
    type: DELETE_USER_INFO,

  }
}


// 通过redux-thunk 在redux中发请求做异步操作，并dispatch action 将用户信息保存到redux中
// export const getUserInfoAction = (value) => {
//   return async (dispatch) => {
//     const result = await reqLogin(value)
//     const userInfo = result.data
//     if (result.status !== 0) return
//     else {
//       if (result.msg) {
//         message.error(result.msg,1)
//       } else {
//         dispatch(saveUserInfo(userInfo))
//       }
//     }
//   }
// }